package unit4.part8;

import java.util.Arrays;

public class EnumTest {
    public static void main(String[] args) {
        System.out.println(Direction.EAST.getName());// 枚举 => 名字
        System.out.println(Arrays.toString(Direction.values()));// 全部可能的枚举值
        System.out.println(Direction.of("东"));// 名字 => 枚举

        Direction direction = Direction.EAST;
        switch (direction) {
            case EAST:
                System.out.println("东");
            case WEST:
            case NORTH:
            case SOUTH:
            default:
                System.out.println("随便");
        }
    }
}

enum Direction {
    EAST("东"), SOUTH("南"), WEST("西"), NORTH("北");
    private final String name;

    Direction(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public static Direction of(String name) {
        for (Direction direction : values()) {
            if (direction.getName().equals(name)) {
                return direction;
            }
        }
        return null;
    }
}
